{template 'web/common/common'}
{template 'web/home/navbar'}
<link rel="stylesheet" type="text/css" href="../addons/kundian_farm/resource/css/style.css" />
<link rel="stylesheet" type="text/css" href="../addons/{php echo $_GPC['m']}/resource/swal/dist/sweetalert2.min.css" />
<div class="panel panel-success">
    <div class="panel-heading">
        <h3 class="panel-title">
            积分商城轮播图>编辑
        </h3>
    </div>
    <div class="panel-body">
        <form id="sign-form" class="form-horizontal" role="form" method="post" action="{url 'site/entry/slide',array('m'=>'kundian_farm','op'=>'integralSaveModel','version_id'=>$_GPC['version_id'])}" name="submit" style="padding: 20px 0;">
            <div class="form-group">
                <label class="col-sm-2 control-label">图片(375*300)</label>
                <div class="col-sm-8">
                    {php echo tpl_form_field_image('slide_src',$list['slide_src']);}
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-2 control-label">状态</label>
                <div class="col-sm-8">
                    {if $list['status']==1}
                    <input type="checkbox" checked class="js-switch" value="1" name="status">
                    {else}
                    <input type="checkbox" class="js-switch" name="status" value="1">
                    {/if}
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-2 control-label">链接板块</label>
                <div class="col-sm-8">
                    <select name="link_type" id="selectLink" class="form-control">
                        <option value="0">请选择</option>
                        <option value="1" <?php if($list['link_type']==1){echo 'selected';}?> >农田选租</option>
                        <option value="2" <?php if($list['link_type']==2){echo 'selected';}?> >家畜领养</option>
                        <option value="3" <?php if($list['link_type']==3){echo 'selected';}?> >农场签到</option>
                        <option value="4" <?php if($list['link_type']==4){echo 'selected';}?> >农场监控</option>
                        <option value="5" <?php if($list['link_type']==5){echo 'selected';}?> >普通商城</option>
                        <option value="6" <?php if($list['link_type']==6){echo 'selected';}?> >团购商城</option>
                        <option value="7" <?php if($list['link_type']==7){echo 'selected';}?> >积分商城</option>
                        <option value="8" <?php if($list['link_type']==8){echo 'selected';}?> >资讯列表</option>
                    </select>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-2 control-label">链接参数</label>
                <div class="col-sm-8">
                    <select name="link_param" id="selectParam" class="form-control">
                        <option value="0">请选择</option>
                    </select>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-2 control-label">排序</label>
                <div class="col-sm-8">
                    <input type="text" class="form-control"  name="rank" value="{$list['rank']}">
                </div>
            </div>
            <div class="form-group">

                <div class="col-sm-offset-2 col-sm-10">
                    <input type="hidden" name="id" value="{$list['id']}">
                    <button type="submit" class="btn btn-success">保存</button>
                    <a class="btn btn-default" href="{url 'site/entry/slide',array('m'=>'kundian_farm','op'=>'integral_slide','version_id'=>$_GPC['version_id'])}">返回</a>
                </div>
            </div>
        </form>
    </div>
</div>

<script>
    require(["../addons/{php echo $_GPC['m']}/resource/swal/dist/sweetalert2.min.js"],function(){
        $(function(){
            var now_select_id=$("#selectLink").val();
            var id=$("input[name='id']").val();
            $.ajax({
                type:"post",
                url:"{url 'site/entry/'.$_GPC['do'],array('m'=>$_GPC['m'],'op'=>'selectLink','version_id'=>$_GPC['version_id'])}",
                data:{select_id:now_select_id,id:id},
                dataType:'json',
                success:function(res){
                    if(res.selectData){
                        var selectData=res.selectData;
                        var str='<option value="0">请选择</option>';
                        for(var i=0;i<selectData.length;i++){
                            if(now_select_id==1){
                                if(selectData[i]['is_select']==1){
                                    str+='<option value="'+selectData[i]['id']+'" selected>'+selectData[i]['land_name']+'</option>';
                                }else{
                                    str+='<option value="'+selectData[i]['id']+'">'+selectData[i]['land_name']+'</option>';
                                }

                            }else if(now_select_id==2){
                                if(selectData[i]['is_select']==1) {
                                    str += '<option value="' + selectData[i]['id'] + '" selected>' + selectData[i]['animal_name'] + '</option>';
                                }else{
                                    str += '<option value="' + selectData[i]['id'] + '">' + selectData[i]['animal_name'] + '</option>';
                                }
                            }else if(now_select_id==5 ||now_select_id==6 ||now_select_id==7){
                                if(selectData[i]['is_select']==1) {
                                    str += '<option value="' + selectData[i]['id'] + '" selected>' + selectData[i]['goods_name'] + '</option>';
                                }else{
                                    str += '<option value="' + selectData[i]['id'] + '">' + selectData[i]['goods_name'] + '</option>';
                                }
                            }else if(now_select_id==8){
                                if(selectData[i]['is_select']==1) {
                                    str += '<option value="' + selectData[i]['id'] + '" selected>' + selectData[i]['title'] + '</option>';
                                }else{
                                    str += '<option value="' + selectData[i]['id'] + '">' + selectData[i]['title'] + '</option>';
                                }
                            }
                        }

                        $('#selectParam').html(str);
                    }
                }
            })


            $("#selectLink").change(function () {
                var select_id=$(this).val();
                $.ajax({
                    type:"post",
                    url:"{url 'site/entry/'.$_GPC['do'],array('m'=>$_GPC['m'],'op'=>'selectLink','version_id'=>$_GPC['version_id'])}",
                    data:{select_id:select_id},
                    dataType:'json',
                    success:function(res){
                        if(res.selectData){
                            var selectData=res.selectData;
                            var str='<option value="0">请选择</option>';
                            for(var i=0;i<selectData.length;i++){
                                if(select_id==1){
                                    str+='<option value="'+selectData[i]['id']+'">'+selectData[i]['land_name']+'</option>';
                                }else if(select_id==2){
                                    str+='<option value="'+selectData[i]['id']+'">'+selectData[i]['animal_name']+'</option>';
                                }else if(select_id==5 ||select_id==6 ||select_id==7){
                                    str+='<option value="'+selectData[i]['id']+'">'+selectData[i]['goods_name']+'</option>';
                                }else if(select_id==8){
                                    str+='<option value="'+selectData[i]['id']+'">'+selectData[i]['title']+'</option>';
                                }
                            }

                            $('#selectParam').html(str);
                        }
                    }
                })
            })

        })
    })
</script>